﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.ObjectModel;

namespace Framework.Constructor.Sql
{
    public class Tabla : ObjetoBase
    {
        public Collection<Columna> Columnas { get; set; }
        public Tabla( Dictionary<String, Object> diccionario )
            : base( diccionario )
        { }

        public override String ToXmlString( String espaciado )
        {
            String nameSpace = String.Format( "Framework.Modelo.Sql.Tabla.{0}", this.Name );
            StringBuilder sb = new StringBuilder();
            sb.Append( String.Format( "{0}<{1}>", espaciado, nameSpace ) );
            sb.Append( Environment.NewLine );
            foreach ( Columna pi in this.Columnas )
            {
                if ( !pi.TipoDeDato.TipoNet.Name.Contains( "Collection" ) )
                {
                    sb.Append( String.Format( "{0}\t<{1} type=\"{2}\">", espaciado, pi.Name, pi.TipoDeDato.TipoNet.FullName ) );
                    sb.Append( Environment.NewLine );
                    sb.Append( String.Format( "{0}\t</{1}>", espaciado, pi.Name ) );
                    sb.Append( Environment.NewLine );
                }
            }
            sb.Append( String.Format( "{0}</{1}>", espaciado, nameSpace ) );
            return sb.ToString();
        }
        public override string ToXmlStringChilds(String espaciado)
        {
            String nameSpace = String.Format( "Columnas type=\"{0}\"", "System.Collections.ObjectModel.Collection" );
            StringBuilder sb = new StringBuilder();
            sb.Append( String.Format( "\t<{0}>", nameSpace ) );
            sb.Append( Environment.NewLine );
            foreach ( Columna item in this.Columnas )
            {
                sb.Append( item.ToXmlString( espaciado + "\t" ) );
                sb.Append( Environment.NewLine );
            }
            sb.Append( String.Format( "\t</{0}>", "Columnas" ) );
            sb.Append( Environment.NewLine );
            return sb.ToString();

        }
    }
}
